﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SlamDunk.MES.Domain.Entities.DefinitionContext;

namespace SlamDunk.MES.Repository.EntityConfigurations.DefinitionContext
{
    /// <summary>
    /// 工艺实体映射配置
    /// </summary>
    public class ProcessConfig : IEntityTypeConfiguration<Process>
    {
        /// <summary>
        /// 配置
        /// </summary>
        public void Configure(EntityTypeBuilder<Process> builder)
        {
            //配置属性
            builder.HasKey(process => process.Id).IsClustered(false);
            builder.HasMany(process => process.Segments).WithOne(segment => segment.Process).IsRequired().OnDelete(DeleteBehavior.Cascade);
            builder.Property(process => process.RunSize).HasPrecision(29, 10);

            //配置索引
            builder.HasIndex(process => process.AddedTime).IsUnique(false).IsClustered();
        }
    }
}
